function selectLocation(lat, lon){
  $("input#lat").val(lat);
  $("input#lon").val(lon);
  var selector = ".locationLabel";
  clearLocation();
  showProcessingMarker(selector);
  $.get('/easysearch/geoLocation/label.do', {lat: lat, lon : lon}, function(data, textStatus){
  $("#locationLabel").val(data);
  hideProcessingMarker(selector);
  });
}
function clearLocation(){
  $("input#lat").val('');
  $("input#lon").val('');
  $("#locationLabel").val('');
}
function showProcessingMarker(selector){
  $(selector + ".processing").show();
}
function hideProcessingMarker(selector){
  $(selector + ".processing").hide();
}
function updatePriceRangeLabel(newMinPrice, newMaxPrice){
  var label = '';
  if(newMinPrice >= minPrice){
    label += ' от ' + newMinPrice + '$';
  }
  if(newMaxPrice <= maxPrice){
    label += ' до ' + newMaxPrice + '$';
  }
  if(!label)
    label = 'любая';
  $("#price-range-label").html(label);
}
var prevPageUrl;
function go2prevPage(){
  document.location.href = prevPageUrl;
}
var nextPageUrl;
function go2nextPage(){
  document.location.href = nextPageUrl;
}
function clearLocation(){
  document.getElementById('lat').value = '';
  document.getElementById('lon').value = '';
}
function addAgentUserReview(flatAdId, url){
  $('#processingAgentUserRating' + flatAdId).show();
  return addUserReview(flatAdId, url);
}
function addBadPhoneUserReview(flatAdId, url){
  $('#processingBadPhoneUserRating' + flatAdId).show();
  return addUserReview(flatAdId, url);
}
function addExpiredAdUserReview(flatAdId, url){
  $('#processingExpiredAdUserRating' + flatAdId).show();
  return addUserReview(flatAdId, url);
}
function addUserReview(flatAdId, url){
  if(loggedIn){
    var userReviewUrl = url + "?flatAdId=" + flatAdId;
    $.get(userReviewUrl, function(data) {
      $('#reviewContainer' + flatAdId).html(data);
    });
  }
  else{
    document.location.href = url;
  }
  return false;
}
// TODO: remove and use one from common.js
function toggleReviewButtons(flatAdId){
  var buttons = $('#reviewButtons' + flatAdId);
  if (buttons.is(":hidden")) {
    buttons.show();
  } else {
    buttons.hide();
  }
}
//TODO: remove and use one from common.js
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}
//TODO: remove and use one from common.js
function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}
//TODO: remove and use one from common.js
function eraseCookie(name) {
  createCookie(name,"",-1);
}
